Spread for ASP.NET 11 Product Documentation
Working with the SaveExcel button on the CommandBar
Spread for ASP.NET 11 Product Documentation > Developer's Guide > Customizing User Interaction > Customizing the Toolbars > Working with the SaveExcel button on the CommandBar

The SaveExcel button on the CommandBar allows users to export spreadsheets into excel files. This button handles user actions by making use of the SaveExcelToResponse() method to save into excel file.

By default, the SaveExcel button is not displayed on the CommandBar. To work with the SaveExcel button, users must ensure that the ShowExcelButton property in the CommandBarInfo class is set to true.

The following image displays the SaveExcel button on the CommandBar.

 

While exporting to an excel file using the SaveExcel button, you can set password to enforce additional access security.

The ShowExcelSecurityPopup property gets or sets whether to display the Set password popup after a user clicks on the SaveExcel button. The following image displays the Set Password pop up.

 

After you set password, your excel file will be saved. If any other user wants to open the file, he/she has to enter a password and the file will be opened only after the password authetication is successful.

Using Code

1. Set the FpSpread component’s ShowExcelButton property to true.

2. Set the FpSpread component’s ShowExcelSecurityPopup property to true.

3. Modify the default filename, password and the save flag.

Example

The first example code displays the SaveExcel button on the CommandBar. The second example code shows a Set Password popup when a user clicks on the SaveExcel button. The third example code modifies the default filename, password and the save flag.

C#
Copy Code
// Display the SaveExcel button on the CommandBar.
FpSpread1.CommandBar.ShowExcelButton = true;

// Show the Set Password popup
FpSpread1.CommandBar.ShowExcelSecurityPopup = true;

// Change the default filename, password and the save flag.
private void SaveExcelHandler(object sender, FarPoint.Web.Spread.SaveExcelEventArgs e)
{
 e.FileName = "MyFile.xlsx";
 e.Password = "MyPassword";
 e.Flag = FarPoint.Excel.ExcelSaveFlags.UseOOXMLFormat;
}
VB
Copy Code
' Display the SaveExcel button on the CommandBar.
FpSpread1.CommandBar.ShowExcelButton = true; 

' Show the Set Password popup
FpSpread1.CommandBar.ShowExcelSecurityPopup = true;

' Change the default filename, password and the save flag
Private Sub SaveExcelHandler(sender As Object, e As FarPoint.Web.Spread.SaveExcelEventArgs)
 e.FileName = "MyFile.xlsx"
 e.Password = "MyPassword"
 e.Flag = FarPoint.Excel.ExcelSaveFlags.UseOOXMLFormat
End Sub

Using the Spread Designer

  1. In the Property Grid, select Spread from the dropdown.
  2. Under Appearance tab, expand the CommandBar.
  3. Set the ShowExcelButton property to true in order to display the SaveExcel button on the CommandBar.
  4. Set the ShowExcelSecurityPopup property to true in order to ensure file security.
  5. Click the SaveExcel button to save into an Excel file. 
  6. In the SetPassword window that appears, enter the password, confirm it and click Ok. 
  7. A file with the default name MyFile.xlsx will be saved to your computer. The saved excel file will be password protected.

  8. Click OK to close the Spread Designer.

Note: The Export to Excel feature has the following limitation:

The SaveExcelToResponse() method doesn't work when Spread is placed in an UpdatePanel control.